package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.InsectPestBean;
import com.project.service.InsectPestService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 虫害
 */
@Controller
@RequestMapping("InsectPest")
public class InsectPestController {


    @Resource
    private InsectPestService insectPestService;


    /**
     * 显示所有虫害
     * @param pageNO
     * @param pageSize
     * @return
     */
    @RequestMapping("/findAllInsectPest")
    @ResponseBody
    public IPage<InsectPestBean> findAllInsectPest(@RequestParam(value = "pageNO", defaultValue = "1") int pageNO,
                                                   @RequestParam(value = "pageSize", defaultValue = "2") int pageSize) {
        return insectPestService.findAllInsectPest(pageNO, pageSize);
    }

    /**
     * 添加新虫害
     * @param insectPestBean
     * @return
     */
    @RequestMapping("/addInsectPest")
    @ResponseBody
    public String addInsectPest(InsectPestBean insectPestBean) {
        insectPestService.addInsectPest(insectPestBean);
        return "添加成功";
    }


    /**
     * 查看详细信息
     * @param insectPestId
     * @return
     */
    @RequestMapping("/findId")
    @ResponseBody
    public InsectPestBean findId(int insectPestId) {
        return insectPestService.findId(insectPestId);
    }

    /**
     * 模糊查询
     * @param pageNO
     * @param pageSize
     * @param insectPestName
     * @param insectPestHost
     * @return
     */
    @RequestMapping("/findName")
    @ResponseBody
    public IPage<InsectPestBean> findName(@RequestParam(value = "pageNO", defaultValue = "1") int pageNO,
                                    @RequestParam(value = "pageSize", defaultValue = "3") int pageSize,
                                    String insectPestName, String insectPestHost) {
        return insectPestService.findName(pageNO, pageSize, insectPestName, insectPestHost);
    }
}
